package com.tsing.basic.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tsing.basic.vo.req.LogPageReqVo;
import com.tsing.basic.vo.resp.LogRespVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author TheTsing
 * @version 1.0
 * @date 2021/4/22 11:38
 */
@Mapper
public interface Log2Mapper {

    @Delete("<script>" +
            "delete from t_log l where l.id in\n" +
            "<foreach collection='ids' item='item' open='(' close=')' separator=',' >\n" +
            "#{item}\n" +
            "</foreach>\n" +
            "</script>")
    void deleteLog(@Param("ids") List<String> ids);

    @Select("<script>" +
            "select l.*\n" +
            "from t_log l\n" +
            "<where>\n" +
            "<if test=\"reqVo.description!=null and reqVo.description!=''\">and l.description like concat('%',#{reqVo.description},'%')</if>\n" +
            "<if test=\"reqVo.startActionDate!=null and reqVo.startActionDate!=''\">and unix_timestamp(l.action_date) &gt;= ( #{reqVo.startActionDate}/1000 )</if>\n" +
            "<if test=\"reqVo.endActionDate!=null and reqVo.endActionDate!=''\">and unix_timestamp(l.action_date) &lt;= ( #{reqVo.endActionDate}/1000 )</if>\n" +
            "</where>\n" +
            "order by l.action_date desc" +
            "</script>")
    List<LogRespVo> logPage(LogPageReqVo reqVo, Page<LogRespVo> page);

}
